/*This class is used to get the history of backup'
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cloudminga.database;

/**
 *
 * @author jyoti
 */
import com.globussoft.util.FormatedFileSize;
import com.globussoft.util.FormatedTime;
import java.sql.*;

public class DataBase_HistoryInfo
{
        Statement statement;
        Connection connection=null;
        ResultSet resultSet=null;
        ResultSet resultSet1;
        CallableStatement callableStatement;
        ResultSetMetaData resultsetMetaData;
        String query;
        String email_Id;
        TableModel table_Model;
        int colCount=0;
        int rowCount;

    public DataBase_HistoryInfo()
    {
        try
        {
            // Establising database connection
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
           connection = DriverManager.getConnection("jdbc:jtds:sqlserver://mssql502.ixwebhosting.com/C230527_masterdatabase","C230527_sumit","Globus1234");
        
         }  // End of try

         catch(Exception exception)
         {
            exception.printStackTrace();
         }// End of catch
      }//end of constructor

    public TableModel get_HistoryInfo(String email)
    {
        int temp;
        int row=0;
         this.email_Id=email;
          try
          {                                                
            callableStatement=connection.prepareCall("{call sp_Pomblast_GetBackupsHisorytByUser(?)}",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
            callableStatement.setString(1, email_Id);
            resultSet=callableStatement.executeQuery();
            // rsmt is ResultSetMetaData to find out the total columns of the table
            resultsetMetaData=resultSet.getMetaData();
            colCount=resultsetMetaData.getColumnCount();
            resultSet.last();
            rowCount=resultSet.getRow();
            resultSet.beforeFirst();
            System.out.println("number of rows are :  "+rowCount);
            table_Model=new TableModel(rowCount,colCount);
            resultSet.beforeFirst();
            //table_Model=new TableModel(3,colCount);
             while(resultSet.next())
              {
                   table_Model.setValueAt(row,0,resultSet.getString(1));
                   table_Model.setValueAt(row,1,resultSet.getString(2));
                   table_Model.setValueAt(row,2,FormatedTime.getFormatedTimeString(resultSet.getLong(3)));//
                   table_Model.setValueAt(row,3,resultSet.getString(4));
                   table_Model.setValueAt(row,4,resultSet.getString(5));
                   table_Model.setValueAt(row,5,FormatedFileSize.getFormatedFileSize(resultSet.getLong(6)));//
                   table_Model.setValueAt(row,6,resultSet.getString(7));
                   table_Model.setValueAt(row,7,FormatedFileSize.getFormatedFileSize(resultSet.getLong(8)));
                   row++;
              }
         }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
      return table_Model;
    }
}
